package data

import (
	"github.com/go-kratos/kratos/pkg/conf/paladin"
)

type MongoCfg struct {
	DbName string
	Coll   string
	Addrs  string
	Source string
	User   string
	Pass   string
}

func NewWarehouseItemMgoUtil() (db *MongoUtil, cf func(), err error) {
	var ct paladin.TOML
	if err = paladin.Get("mongo.toml").UnmarshalTOML(&ct); err != nil {
		return
	}

	cfg := &MongoCfg{}
	if err = ct.Get("Warehouse-Item").UnmarshalTOML(cfg); err != nil {
		return
	}

	db = NewMongoUtil(cfg)
	cf = func() { db.Close() }
	return
}

func NewWarehouseMgoUtil() (db *Mu, cf func(), err error) {
	var ct paladin.TOML
	if err = paladin.Get("mongo.toml").UnmarshalTOML(&ct); err != nil {
		return
	}

	cfg := &MongoCfg{}
	if err = ct.Get("Warehouse").UnmarshalTOML(cfg); err != nil {
		return
	}

	db = NewMu(cfg)
	cf = func() { db.Close() }
	return
}
